<?php
$client_id = "bfbda1c944ce4080b32796019b7917e4";
$redirect_uri = "http://darkphvweb.com.br/instagran/login.php";
$client_secret = "15d558090545471188c2840d3778b041";

if (!empty($_REQUEST['code']))
{
    $url = "https://api.instagram.com/oauth/access_token";
    $access_token_parameters = array(
        'client_id' => $client_id,
        'client_secret' => $client_secret,
        'grant_type' => 'authorization_code',
        'redirect_uri' => $redirect_uri,
        'code' => $_REQUEST["code"]
    );
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $access_token_parameters);
    $result = curl_exec($curl);

    $retorno = json_decode($result);
    
    
            echo "<pre>";
        print_r($retorno);
        echo "</pre>";
    ?>
    <p><?php echo $retorno->user->id; ?></p>
    <h1><?php echo $retorno->user->username; ?></h1>
    <h3><?php echo $retorno->user->full_name; ?></h3>
    <img src="<?php echo $retorno->user->profile_picture; ?>"/>
    <?php
    if (!empty($retorno->user->id))
    {
        $curl2 = curl_init();
        curl_setopt($curl2, CURLOPT_URL, "https://api.instagram.com/v1/users/".$retorno->user->id."/media/recent/?access_token=".$retorno->access_token);
        curl_setopt($curl2, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($curl2, CURLOPT_SSL_VERIFYPEER, false);
        $result2 = curl_exec($curl2);
        curl_close($curl2);

        $retorno2 = json_decode($result2);


        echo "<pre>";
        print_r($retorno2);
        echo "</pre>";
    }
}
else
{
    header('Location: https://api.instagram.com/oauth/authorize/?client_id=' . $client_id . '&redirect_uri=' . $redirect_uri . '&response_type=code');
}
?>